/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

namespace DaveSexton.DocProject.DocSites
{
	public struct IndexMatch : IEquatable<IndexMatch>
	{
		#region Public Properties
		public string Title { get { return entry.Title; } }

		public string VirtualPath { get { return entry.VirtualPath; } }

		public IndexEntry Entry { get { return entry; } }

		public string TopicType { get { return msHelp.TopicType; } }

		public string FullTitle { get { return msHelp.Title; } }

		public string ApiName { get { return msHelp.ApiName; } }

		public string ApiLocation { get { return msHelp.ApiLocation; } }

		public string ApiType { get { return msHelp.ApiType; } }

		public string Locale { get { return msHelp.Locale; } }

		public string Abstract { get { return msHelp.Abstract; } }

		public int Rank { get { return rank; } }
		#endregion

		#region Private / Protected
		private readonly IndexEntry entry;
		private readonly MSHelpEntry msHelp;
		private readonly int rank;
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="IndexMatch" /> structure.
		/// </summary>
		public IndexMatch(IndexEntry entry)
			: this(entry, entry.MSHelp)
		{
		}

		/// <summary>
		/// Constructs a new instance of the <see cref="IndexMatch" /> structure.
		/// </summary>
		public IndexMatch(IndexEntry entry, int rank)
			: this(entry, entry.MSHelp, rank)
		{
		}

		/// <summary>
		/// Constructs a new instance of the <see cref="IndexMatch" /> structure.
		/// </summary>
		public IndexMatch(IndexEntry entry, MSHelpEntry msHelp)
		{
			this.entry = entry;
			this.msHelp = msHelp;
			rank = 0;
		}

		/// <summary>
		/// Constructs a new instance of the <see cref="IndexMatch" /> structure.
		/// </summary>
		public IndexMatch(IndexEntry entry, MSHelpEntry msHelp, int rank)
		{
			this.entry = entry;
			this.rank = rank;
			this.msHelp = msHelp;
		}
		#endregion

		#region Methods
		public IndexMatch IncrementRank()
		{
			return new IndexMatch(entry, rank + 1);
		}

		public IndexMatch AddRank(int count)
		{
			return new IndexMatch(entry, rank + count);
		}

		public override string ToString()
		{
			return entry.File;
		}

		public override bool Equals(object obj)
		{
			if (obj is IndexMatch)
				return Equals((IndexMatch) obj);
			else
				return base.Equals(obj);
		}

		public override int GetHashCode()
		{
			return entry.GetHashCode();
		}

		public static bool operator ==(IndexMatch match1, IndexMatch match2)
		{
			return match1.Equals(match2);
		}

		public static bool operator !=(IndexMatch match1, IndexMatch match2)
		{
			return !match1.Equals(match2);
		}
		#endregion

		#region IEquatable<IndexMatch> Members
		public bool Equals(IndexMatch other)
		{
			return entry == other.entry;
		}
		#endregion
	}
}
